﻿using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public enum MsgID
{
    NullTrans = -1,
    EndBattle = 0, //回合结束
    Max = 99


}
/// <summary>
/// 消息中心
/// </summary>
public class MessageCenter : Singleton<MessageCenter>
{
    Dictionary<MsgID, Action<object>> dic = new Dictionary<MsgID, Action<object>>();
    /// <summary>
    /// 添加侦听
    /// </summary>
    /// <param name="iD"></param>
    /// <param name="action"></param>
    public void OnAddListener(MsgID iD,Action<object> action)
    {
        if (dic.ContainsKey(iD))
        {
            dic[iD] += action;
        }
        else
        {
            dic.Add(iD, action);
        }
    }
    /// <summary>
    /// 移除侦听
    /// </summary>
    /// <param name="iD"></param>
    /// <param name="action"></param>
    public void OnRemoveListener(MsgID iD,Action<object> action)
    {
        if (dic.ContainsKey(iD))
        {
            dic[iD] -= action;
        }
    }
    /// <summary>
    /// 广播消息
    /// </summary>
    /// <param name="iD"></param>
    /// <param name="obj"></param>
    public void BroadCast(MsgID iD,params object[] obj)
    {
        if (dic[iD]!=null)
        {
            dic[iD](obj);
        }
    }
}
